package com.wwz.controller;

import com.netflix.loadbalancer.RetryRule;
import com.wwz.annotation.BusinessJudge;
import com.wwz.config.RedisLuaTemplate;
import com.wwz.service.OrderService;
import com.wwz.service.OrderServiceImpl;
import com.wwz.service.TccAction;
import com.wwz.tcc.TccOrderService;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

/**
 * @author wwz
 */
@Controller
@RequestMapping("/api")
public class OrderController {

    @Autowired
    RestTemplate restTemplate;
    @Autowired
    private OrderService orderServiceImpl;
    @Autowired
    private TccOrderService tccAction;
 /*   @Autowired
    private StringRedisTemplate stringRedisTemplate;*/
    @Autowired
    private RedisLuaTemplate redisLuaTemplate;

    @RequestMapping("create")
    @ResponseBody
    @BusinessJudge(key = "orderInsert")
    public String testInsert(String productId){
        try {
            if(StringUtil.isNullOrEmpty(productId)){
                productId = "1";
            }
                return ""+orderServiceImpl.insert();

/*
            if(redisLuaTemplate.lock(productId,System.currentTimeMillis()+"",10)){
*/

           /* }
            return "人数请求过多，请稍候重试！" ;*/
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }

    }
    @RequestMapping("/user")
    public String getUser(){
        return  "login";
    }
}
